#pragma once


#include "GridCellsHolder.h"
#include "pch.h"

namespace WFC = Windows::Foundation::Collections;
using namespace std;
using namespace Platform;
using namespace Windows::UI::Xaml::Data;
using namespace Windows::UI::Xaml::Interop;

namespace TicTacToe
{
	static const int HUMAN_PLAYER = 1;
	static const int COMPUTER_PLAYER = 2;

	[Windows::UI::Xaml::Data::Bindable]
	public ref class GameModel sealed: Windows::UI::Xaml::Data::INotifyPropertyChanged
	{
	private:
		 vector<vector<int>> m_cellGrid;
		 map<int, map<int, int>> m_numbers;
		 GridCellsHolder^ m_cells;
		 int m_currentPlayer;
		 int m_winnerPlayer;

		 int GetWinnerInRow(Platform::Collections::Vector<int>^ playersInRow);
		 int GetWinnerInDiagonal(Platform::Collections::Vector<int>^ playersInDiagonal);

	public:
		GameModel(void);
		property int CurrentPlayer { int get(void); void set(int);};
		property int WinnerPlayer { int get(void); void set(int);};
		property bool GameOver;

		property int GridRows;
		property int GridColumns;

		property GridCellsHolder^ Cells {GridCellsHolder^ get(); void set(GridCellsHolder^);};

		void InitializeGame();

		int CheckForHorizontalWinner();
		int CheckForVerticalWinner();
		int CheckForDiagonalWinner();

		virtual event PropertyChangedEventHandler^ PropertyChanged;
		void RaisePropertyChanged(String^ name);
	};
}